package rtp.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jdom.Element;

import rtp.model.*;
import rtp.model.dao.*;
import rtp.model.manager.*;

/**
 * Servlet implementation class CriarTarefasServlet
 */
@WebServlet("/CriarTarefasServlet")
public class CriarTarefasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public CriarTarefasServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		Tarefa tarefa = new Tarefa();
			tarefa.setId(request.getParameter("txtId"));
			tarefa.setTitulo(request.getParameter("txtTitulo"));
			tarefa.setPrazo(request.getParameter("txtPrazo"));
			tarefa.setDetalhes(request.getParameter("txtDetalhes"));
			tarefa.setResponsavel(request.getParameter("txtResponsavel"));			
				
		String path = getServletContext().getInitParameter("Dados");
		ITarefaDAO dao = new TarefaDAO(path);
		TarefaManager manager = new TarefaManager(dao);
		manager.criarTarefa(tarefa);
		
		
		request.setAttribute("tarefas", manager.retornarTarefa(tarefa.getId()));

		RequestDispatcher view = request.getRequestDispatcher("result.jsp");
		
		view.forward(request, response);
	}

}
